package com.wenwei.paper.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wenwei.paper.R;
import com.wenwei.paper.base.BaseActivity;
import com.wenwei.paper.bean.MessageBean;
import com.wenwei.paper.net.ApiManager;
import com.wenwei.paper.net.BaseSubscriber;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13.
 */
public class MessageNotifyActivity extends BaseActivity {
    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.message_num)
    TextView messageNum;
    @Bind(R.id.message_time)
    TextView messageTime;
    @Bind(R.id.num_text)
    TextView numTv;

    private boolean isInitView = false;
    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_message_notify;
    }

    @Override
    protected void initView() {
        super.initView();
        isInitView = true;
        baseTitle.setText("消息通知");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.base_back, R.id.message_notify_rl})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.message_notify_rl:
                goActivity(mContext, ReplenishmentNotifyActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        super.initData();
        getMessage();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(isInitView){
            getMessage();
        }
    }

    private BaseSubscriber<MessageBean> messageSubscriber;

    private void getMessage() {
        messageSubscriber = new BaseSubscriber<MessageBean>(mContext) {
            @Override
            public void onSuccess(MessageBean messageBean) {
                messageNum.setText("您有"+messageBean.getCount()+"条新的补货清单，请查收！");
                messageTime.setText(messageBean.getTime());
                if(messageBean.getCount()>0){
                    numTv.setVisibility(View.VISIBLE);
                    numTv.setText(""+messageBean.getCount());
                }
            }
        };
        ApiManager.getInstance().MessageNotify(messageSubscriber);
    }
}
